package com.woniuxy.amusementparkos.controller.lzw;


import com.woniuxy.amusementparkos.entity.lsy.Pos;
import com.woniuxy.amusementparkos.entity.lzw.AdjustMoneyInfo;
import com.woniuxy.amusementparkos.entity.lzw.ShiftExchangeInfo;
import com.woniuxy.amusementparkos.entity.lzw.StatusInfo;
import com.woniuxy.amusementparkos.entity.wyh.Balance_Change;
import com.woniuxy.amusementparkos.exception.lzw.KnownException;
import com.woniuxy.amusementparkos.exception.lzw.unifyhanding.code.enumwarehouse.PublicEnumCode;
import com.woniuxy.amusementparkos.service.lzw.ShiftExchangeInfoService;
import com.woniuxy.amusementparkos.service.wyh.Balance_ChangeService;
import com.woniuxy.amusementparkos.util.lzw.result.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (ShiftExchangeInfo)表控制层
 *     交接班功能实现
 *
 * @author makejava
 * @since 2020-04-27 21:00:43
 */
@RestController
@RequestMapping("shiftExchangeInfo")
public class ShiftExchangeInfoController {
    /**
     * 服务对象
     */
    @Resource
    private ShiftExchangeInfoService shiftExchangeInfoService;

    @Resource
    private Balance_ChangeService balance_changeService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ShiftExchangeInfo selectOne(Integer id) {
        return this.shiftExchangeInfoService.getById(id);
    }

    /**
     * 插入交接班信息
     *    作用：前台交接班时需要存入数据
     *
     * @param shiftExchangeInfo
     * @return 插入的信息
     */
    @PostMapping("insert")
    public ResponseResult<ShiftExchangeInfo> insert(ShiftExchangeInfo shiftExchangeInfo){

        if(shiftExchangeInfo == null){
            throw new KnownException(PublicEnumCode.NPE);
        }

        return new ResponseResult<ShiftExchangeInfo>(
                PublicEnumCode.SUCCESS,
                this.shiftExchangeInfoService.insert(shiftExchangeInfo));
    }

    /**
     * 根据 posID 获取余额变动
     *
     * @param pos_id pos机id
     * @return 余额变动list
     */
    @GetMapping("listAllByPosId")
    public ResponseResult<List<Balance_Change>> listAllByPosId(Integer pos_id){
        if(pos_id == null){
            throw new KnownException(PublicEnumCode.NPE);
        }
        return new ResponseResult<List<Balance_Change>>(PublicEnumCode.SUCCESS,this.balance_changeService.getAllByPosid(pos_id));
    }

    /**
     * 查询单台POS现金总额
     *
     *
     * @param pos_id pos机id
     * @return 现金总额
     */
    @GetMapping("getTotalMoneyByPosIdAndCashPay")
    public ResponseResult<Double> listAllByPosIdAndCash(Integer pos_id){
        if(pos_id == null){
            throw new KnownException(PublicEnumCode.NPE);
        }
        return new ResponseResult<Double>(
                PublicEnumCode.SUCCESS,
                // charge_type = 1，代表：现金
                this.balance_changeService.getTotalbyPos_idAndCharge_type(pos_id, 1));
    }

    /**
     * 查询单台POS支付宝总额
     *
     * @param pos_id pos机id
     * @return 支付宝总额
     */
    @GetMapping("getTotalMoneyByPosIdAndAliPay")
    public ResponseResult<Double> listAllByPosIdAndAliPay(Integer pos_id){
        return new ResponseResult<Double>(
                PublicEnumCode.SUCCESS,
                // charge_type = 2，代表：支付宝
                this.balance_changeService.getTotalbyPos_idAndCharge_type(pos_id, 2));
    }

}